﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Task.Logic;
using Task.Entity;

namespace Task
{
    public partial class ESI_TBConfigList : System.Web.UI.Page
    {
        ESI_TBConfigLogic _logic = new ESI_TBConfigLogic();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtProcessName.Text = Request.QueryString["ProcessName"];
                if (!string.IsNullOrEmpty(txtProcessName.Text))
                {
                    divQuery.Style["display"] = "none";
                }
                BindGrid();
            }
        }

        void BindGrid()
        {
            List<ESI_TBConfigEntity> dt = _logic.GetList(GetWhere());
            Repeater1.DataSource = dt;
            Repeater1.DataBind();
        }

        string GetWhere()
        {
            string where = "";
            if (!string.IsNullOrEmpty(txtProcessName.Text))
            {
                where = " and ProcessName like '%" + txtProcessName.Text + "%'";
            }
            return where;
        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {
            Response.Redirect("ESI_TBConfigDetail.aspx?ProcessName=" + txtProcessName.Text);
        }


        protected void btnQuery_Click(object sender, EventArgs e)
        {
            BindGrid();
        }
        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                
                string str = e.CommandArgument.ToString().Trim();
                _logic.DeleteConfig(str.Split('|')[0], str.Split('|')[1]);
                
                BindGrid();
                Page.ClientScript.RegisterStartupScript(this.GetType(), "msg", "<script>alert('删除成功');</script>");
                return;

            }
        }
    }
}